package com.example.sjm.activity_bysjm;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class MainActivity extends AppCompatActivity {
    List<ListViewModel> list1=new ArrayList<>();
    ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Bmob.initialize(this, "dfb070b70fb6d635bbecf1309049e49f");

        listView=findViewById(R.id.list);
        BmobQuery<Activity> bmobQuery=new BmobQuery<>();
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                Intent intent=new Intent();
                System.out.println("list"+list1.get(i).getActivity_id());
                intent.putExtra("id",list1.get(i).getActivity_id());
                intent.setClass(MainActivity.this,Activity_content.class);
                startActivity(intent);
            }
        });
        bmobQuery.findObjects(new FindListener<Activity>() {
            @Override
            public void done(List<Activity> list, BmobException e) {
                if(e==null){
                    for(Activity listViewModel : list){
                        ListViewModel listViewModel1=new ListViewModel();
                        listViewModel1.setImgUrl( listViewModel.getActivity_photo().getFileUrl());
                        listViewModel1.setName(listViewModel.getActivity_name());
                        listViewModel1.setActivity_id(listViewModel.getActivity_id());
                        list1.add(listViewModel1);
                        System.out.println("bmob"+listViewModel.getActivity_photo().getFileUrl()+"  "+listViewModel.getActivity_name()+" "+listViewModel.getActivity_id());
                    }
                    listView.setAdapter(new ListViewAdapter(MainActivity.this,list1));



                }

            }
        });







    }
}
